using System;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Auto.Web.Common;
using Auto.Components;
using Auto.Data.Security;

namespace BaseSystem
{
    public partial class ModifyPWD : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (SessionBox.User == null)
            {
                Jscript.Redirect("timeout.aspx");
            }
            if (!IsPostBack)
            {
                Users users = SessionBox.User;
                lblUserID.Text = users.UserID;
                lblUserName.Text = users.UserName;
            }
        }
        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            string msg = "Original Password is not correct! Change password fail.";
            Users user = SessionBox.User;

            string oldPwd = StrHelper.Encrypt(this.txtOldPwd.Text);

            string newPwd = StrHelper.Encrypt(this.txtNewPwd.Text);
            int? result = null;
            try
            {
                result = user.ChangePWD(user.UserID, oldPwd, newPwd);
                if (result.HasValue)
                {
                    if (result.Value > 0)
                    {
                        msg = "Change password successfully!";
                    }
                    else
                    {
                        msg = "Change password failure!";
                    }
                }
                Jscript.AjaxAlert(this, msg);
            }
            catch (Exception ex)
            {
                Jscript.AjaxAlert(this, ex.Message);
            }
            
        }
    }
}
